#include <cppunit/config/SourcePrefix.h>
#include "TestFollows.h"
#include <string>

void TestFollows::setUp() {
	follows = Follows();
	follows.addFollows(1,2);
	follows.addFollows(2,3);
	follows.addFollows(4,5);
	follows.addFollows(5,6);
	follows.addFollows(3,7);
	//[1, 2, 3, 7]
	//[4, 5, 6]
}

void TestFollows::tearDown() {
}

CPPUNIT_TEST_SUITE_REGISTRATION( TestFollows );

void TestFollows::testAddFollows(){
	int index1 = follows.addFollows(7,8);
	int index2 = follows.addFollows(8,9);

	CPPUNIT_ASSERT_EQUAL_MESSAGE("6th item added; index 5", 5, index1);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("7th item added; index 6", 6, index2);
}

void TestFollows::testGetFollows(){
	vector<pair<int,int>> anyany = follows.getFollows(ANYVALUE, ANYVALUE);
	int size = anyany.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("All results return", 5, size);

	vector<pair<int,int>> anynum = follows.getFollows(ANYVALUE, 7);
	size = anynum.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Only (allowed) 1 result to be found", 1, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("One result (3,7)", 3, anynum.at(0).first);

	vector<pair<int,int>> numany = follows.getFollows(1, ANYVALUE);
	size = numany.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Only (allowed) 1 result to be found", 1, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("One result (1,2)", 2, numany.at(0).second);

	vector<pair<int,int>> numnum = follows.getFollows(5, 6);
	size = numnum.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("1 result found", 1, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("one result (5,6)", 5, numnum.at(0).first);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("one result (5,6)", 6, numnum.at(0).second);

	vector<pair<int,int>> none = follows.getFollows(1, 4);
	size = none.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("no result found", 0, size);

	none = follows.getFollows(2, 1);
	size = none.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("no result found", 0, size);
}

void TestFollows::testGetFollowsStar(){

	vector<pair<int,int>> anyanyStar = follows.getFollowsStar(ANYVALUE, ANYVALUE);
	int size = anyanyStar.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("9 (5+4) results return, i.e. + (1,3), (1,7), (2,7), (4,6)", 9, size);
	
	vector<pair<int,int>> anynumStar = follows.getFollowsStar(ANYVALUE, 7);
	size = anynumStar.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("3 results found, i.e. (1,7), (2,7), (3,7)", 3, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("first result (1,7)", 1, anynumStar.at(0).first);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("second result (2,7)", 2, anynumStar.at(1).first);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("third result (3,7)", 3, anynumStar.at(2).first);
	
	vector<pair<int,int>> numanyStar = follows.getFollowsStar(4, ANYVALUE);
	size = numanyStar.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("2 results found, i.e. (4,5), (4,6)", 2, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("first result (4,5)", 5, numanyStar.at(0).second);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("second result (4,6)", 6, numanyStar.at(1).second);
	
	vector<pair<int,int>> numnumStar = follows.getFollowsStar(4, 6);
	size = numnumStar.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("One result found only", 1, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("one result (4,6)", 4, numnumStar.at(0).first);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("one result (4,6)", 6, numnumStar.at(0).second);
	
	vector<pair<int,int>> none = follows.getFollowsStar(7, 1);
	size = none.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("No result found", 0, size);
	
	none = follows.getFollowsStar(7, ANYVALUE);
	size = none.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("No result found", 0, size);

	none = follows.getFollowsStar(ANYVALUE, 4);
	size = none.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("No result found", 0, size);
}